package com.corgi.encrypt;

import com.corgi.encrypt.util.Base64Util;
import com.corgi.encrypt.util.RsaUtil;

/**
 * @title: Test
 * @description:
 * @author: dengmiao
 * @create: 2019-10-23 14:02
 **/
public class Test {

    public static void main(String[] args) throws Exception {
        // 阿里巴巴密钥生成工具 https://ideservice.alipay.com/ide/getPluginUrl.htm?clientType=assistant&platform=win&channelType=WEB
        String data = "hello world";
        String publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArkDK6QM+edJrQJeuy7VdnCh4CSt7yolgFAPKxLq/5K9lg2BXV1/H1UmhwdD5FBjKDjIxcgus5l0vF/3XYUFcH4MBnR3s/uK26qbEOfSGHaYqxuDKGgOUEpY5pSt5FVdf/awuK2lxog4EMsW30aE0oXj/ULG9grqKUrVbOzkoFX5x4NKcPECII69ydgmmoeMeURueu7vP/kQQcoc1tR12oRpGaD3gfn1L1QUsftPq65JUTgl4W8PObJnMJQ/pnI5hNlWJ3c89+Gka20bvjBGqwaALj2n2HDyLszKq1gtv8B3N7PT7imM/c7+vPpifs3ZtR+wzmm0sDzHa0I3rZEGmBQIDAQAB",
                privateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCuQMrpAz550mtAl67LtV2cKHgJK3vKiWAUA8rEur/kr2WDYFdXX8fVSaHB0PkUGMoOMjFyC6zmXS8X/ddhQVwfgwGdHez+4rbqpsQ59IYdpirG4MoaA5QSljmlK3kVV1/9rC4raXGiDgQyxbfRoTSheP9Qsb2CuopStVs7OSgVfnHg0pw8QIgjr3J2Caah4x5RG567u8/+RBByhzW1HXahGkZoPeB+fUvVBSx+0+rrklROCXhbw85smcwlD+mcjmE2VYndzz34aRrbRu+MEarBoAuPafYcPIuzMqrWC2/wHc3s9PuKYz9zv68+mJ+zdm1H7DOabSwPMdrQjetkQaYFAgMBAAECggEBAIImlugPqjxndABcywwQPQkEGRQQTHfsv7xzUKI8MlPmxdWowdPbEHE4e/89zKy8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9qA4n5jFomBqr6ru7nVAV6Td+t53trerkeNakUBTVXN9u6MMxw2zKYXwjd6dpXwS0QswivxHQYFBZRA==";
        byte[] encData = RsaUtil.encrypt(data.getBytes(), publicKey);
        String base64Str = Base64Util.encode(encData);
        System.out.println(base64Str);
        byte[] decData = RsaUtil.decrypt(Base64Util.decode(base64Str), privateKey);
        System.out.println(new String(decData));
        System.out.println(Base64Util.encode(data.getBytes()));
    }
}
